<?php
namespace app\api\controller;

use app\common\model as M;

/**
 *
 */
class Article extends \app\api\ApiBase
{
    public $model = '\app\common\model\Article';

    /**
     * @Author   FW
     * @DateTime 2021-05-17
     * @Email    123763712@qq.com
     * @param    integer          $id [description]
     * @return   [type]               [description]
     */
    public function agreement ( )
    {
        return $this->returnSuccess($this->_viewByCate('用户协议'));
    }

    /**
     * 隐私政策
     */
    public function privacy ( )
    {
        return $this->returnSuccess($this->_viewByCate('隐私政策'));
    }

    /**
     * 关于我们
     */
    public function aboutus ( )
    {
        return $this->returnSuccess($this->_viewByCate('关于我们'));
    }

    /**
     * 通过类别名查看单条文本数据，适用于注册协议，培训合同等
     * @Author   FW
     * @DateTime 2021-06-10
     * @Email    123763712@qq.com
     * @param    [type]           $cate_name [description]
     * @return   [type]                      [description]
     */
    protected function _viewByCate($cate_name)
    {
        $content = '';
        $cid = M\ArticleCategory::where('cate_name',$cate_name)->where(['is_del' => 0,'status' => 1])->value('id');

        if ( $cid > 0 ) {
            $content = M\Article::where('cate_id' , $cid)->where('status',1)->order('version desc')->limit(1)->value('content');
        }

        if ( $content ) {
            $content = htmlspecialchars_decode($content);
        } else {
            $content = '<p style="font-weight:bold">文章不存在</p>';
        }
        return $content;
    }
}//Class End